package com.recruit.g1.user.base.response;

public class JsonResult<T> {
    private int code;
    private String message;
    private T data;

    public JsonResult() {
    }

    public JsonResult(StatusCode statusCode) {
        this.code = statusCode.getCode();
        this.message = statusCode.getMessage();
    }

    public JsonResult(StatusCode statusCode, T data) {
        this.code = statusCode.getCode();
        this.message = statusCode.getMessage();
        this.data = data;
    }

    public JsonResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> JsonResult<T> success() {
        return new JsonResult<>(StatusCode.SUCCESS);
    }

    public static <T> JsonResult<T> success(T data) {
        return new JsonResult<>(StatusCode.SUCCESS, data);
    }

    public static <T> JsonResult<T> fail() {
        return new JsonResult<>(StatusCode.FAIL);
    }

    public static <T> JsonResult<T> fail(String message) {
        return new JsonResult<>(StatusCode.FAIL.getCode(), message, null);
    }

    public static <T> JsonResult<T> error(StatusCode statusCode) {
        return new JsonResult<>(statusCode);
    }

    public static JsonResult ok(Object data) {
        return new JsonResult(200, "成功", data);
    }

    public static JsonResult ok() {
        return new JsonResult(200, "成功","");
    }

    // Getters and Setters
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}